//
//  ViewController.m
//  HealthKitManager
//
//  Created by JuneLee on 2018/11/9.
//  Copyright © 2018 JuneLee. All rights reserved.
//

#import "ViewController.h"
#import "YLHealthKitManager.h"
#import "YLDSyetemAuthorizationManager.h"
#import "DetailViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [[YLHealthKitManager sharedManager] requestAuthorizationCompletion:^(BOOL success, NSError * _Nullable error) {
        if (success) {
            NSLog(@"授权成功");
        }
    }];
    
    //获取
    
    [[YLHealthKitManager sharedManager] gethealthKitDataWithHealthKitType:(YLHealthKitTypeStepCount) startDate:[NSDate dateWithTimeIntervalSince1970:1542107221] endDate:[NSDate date] completion:^(NSArray<YLHealthKitModel *> * _Nullable results, NSError * _Nullable error) {
        if (results) {
            NSLog(@"%@",results);
        }
    }];
     
    
//    NSMutableArray *temp4 = [NSMutableArray array];
//    for (int i = 0; i < 5000; i ++) {
//        YLHealthKitModel *model = [[YLHealthKitModel alloc] init];
//        model = [model initHeight:0 weight:100 * 1000 fatWeight:33.5 * 1000 bodyFat:32.5/100.0 bmi:16.7 bmr:1420 date:[NSDate date]];
//        if (i == 2) {
//            model = [model initheartRate:99 startDate:[NSDate date] endDate:[NSDate date]];
//        }
//        [temp4 addObject:model];
//    }
//
//    [[YLHealthKitManager sharedManager] writeHistoryData:^(YLHealthKitConfig * _Nonnull config) {
//        config.userId = @"222";
//        config.healthArray = temp4;
//    } completion:^(BOOL success, NSError * _Nullable error) {
//
//    }];
    
    
//    //写入秤数据
//    [[YLHealthKitManager sharedManager] writeHealthKitDataBlock:^(YLHealthKitModel * _Nonnull healthModel) {
//        healthModel = [healthModel initHeight:158.0/100.0 weight:40.65 * 1000 fatWeight:23.5 * 1000 bodyFat:22.5/100.0 bmi:16.7 bmr:1220 date:[NSDate date]];
//
//    } completion:^(BOOL success, NSError * _Nullable error) {
//
//    }];


    
//    NSMutableArray *temp = [NSMutableArray array];
//    for (int i = 0; i < 4; i ++) {
//        YLHealthKitModel *model = [[YLHealthKitModel alloc] init];
//        model = [model initStep:5452 startDate:[NSDate dateWithTimeIntervalSince1970:1542107221] endDate:[NSDate date]];
//        [temp addObject:model];
//    }
//
//    NSMutableArray *temp1 = [NSMutableArray array];
//    for (int i = 0; i < 3; i ++) {
//        YLHealthKitModel *model = [[YLHealthKitModel alloc] init];
//        model = [model initSleepType:SleepTypeInBed startDate:[NSDate dateWithTimeIntervalSince1970:1542107221] endDate:[NSDate date]];
//        [temp1 addObject:model];
//    }
//
//    NSMutableArray *temp2 = [NSMutableArray array];
//    for (int i = 0; i < 4; i ++) {
//        YLHealthKitModel *model = [[YLHealthKitModel alloc] init];
//        model = [model initheartRate:88 startDate:[NSDate dateWithTimeIntervalSince1970:1542107221] endDate:[NSDate date]];
//        [temp2 addObject:model];
//    }
//    //保存步数，睡眠，心率数据
//    [[YLHealthKitManager sharedManager] writeBandHealthKitData:^(NSMutableArray<YLHealthKitModel *> * _Nonnull stepArray, NSMutableArray<YLHealthKitModel *> * _Nonnull sleepArray, NSMutableArray<YLHealthKitModel *> * _Nonnull heartArray) {
////        [stepArray addObjectsFromArray:temp];
//        [sleepArray addObjectsFromArray:temp1];
//        [heartArray addObjectsFromArray:temp2];
//    } completion:^(BOOL success, NSError * _Nullable error) {
//
//    }];
    
    
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    NSLog(@"点击");
    DetailViewController *vc = [[DetailViewController alloc]init];
    [self presentViewController:vc animated:YES completion:nil];
}

@end
